package com.lili.collection.core.runner.result;

import lombok.Data;

/**
 *描述: 运行结果
 *@date:2023/3/19  23:41
 *@author:lili
 */
@Data
public class RunnerResult<T>{

    private int totalRecordCount=0;

    private int successRecordCount=0;

    private int errorRecordCount=0;

    private ErrOutputData errOutputData=new ErrOutputData();

    private T resultInfo;

    private boolean successed = true;

    public void addTotalCount(int count){
        totalRecordCount+=count;
    }

    public void addSuccessCount(int count){
        successRecordCount+=count;
    }

    public void addErrorCount(int count){
        errorRecordCount+=count;
    }

    public void decrementCount(int deleteOffsetNum){
        if(successRecordCount>=deleteOffsetNum){
            successRecordCount-=deleteOffsetNum;
        }
    }

    public boolean canPutDown(){
        return errOutputData.canPutDown();
    }

    public void setMaxErrorRecordSize(int maxErrorRecordSize){
        errOutputData.setMaxErrorSize(maxErrorRecordSize);
    }

    public void mergeErrorRecord(ErrOutputData errorOutput){
        if(errorOutput==null){
            return;
        }
        errOutputData.setFirstBatchError(errorOutput.isFirstBatchError());
        errOutputData.addErrorTotal(errorOutput.getErrorTotal());
        errOutputData.addAllErrorValueDetails(errorOutput.getErrorValueDetailList());
        errOutputData.mergeErrorInfo(errorOutput.getErrorStatistics());
    }
}